package com.no.hq.controller.stu;

import com.no.hq.pojo.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.Date;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

@RequestMapping("/stu")
@Controller
@Slf4j
public class StuController {

    @RequestMapping("demo1")
    public String demo1(Model model) {
        Student stu = new Student();
        stu.setStuId(1001).setStuName("赵一").setStuBirthday(null).setStuAge(21).setStuSex("女");
        model.addAttribute("stu", stu);
        return "stu/show1";
    }

    @RequestMapping("demo2")
    public String demo2(Model model) {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(1, "赵一", 21, null, "男"));
        stuList.add(new Student(2, "钱二", 22, null, "女"));
        stuList.add(new Student(3, "张三", 23, null, "男"));
        stuList.add(new Student(4, "李四", 24, null, "女"));
        Calendar cal = new GregorianCalendar();
        cal.set(1999, 4, 30);
        Student stu1 = new Student(5, "周五", 25, cal.getTime(), "男");
        Student stu2 = new Student(6, "吴六", 26, Date.from(LocalDateTime.
                of(2001, 6, 28, 23, 30, 30).
                        atZone(ZoneId.systemDefault()).toInstant()), "女");
        stuList.add(stu1);
        stuList.add(stu2);
        model.addAttribute("stuList", stuList);
        return "stu/show2";
    }

    @RequestMapping("demo3")
    public String demo3(Model model) {
        Map<String, Student> stuMap = new LinkedHashMap<>();
        stuMap.put("s1", new Student(1, "赵一", 21, null, "男"));
        stuMap.put("s2", new Student(2, "钱二", 22, null, "女"));
        stuMap.put("s3", new Student(3, "孙三", 23, null, "男"));
        stuMap.put("s4", new Student(4, "李四", 24, null, "女"));
        model.addAttribute("stuMap", stuMap);
        return "stu/show3";
    }
}
